package com.xoa.dev.pz.controller;

import com.xoa.dev.pz.model.PzKeyPetitionWithBLOBs;
import com.xoa.dev.pz.service.impl.PzKeyPetitionService;
import com.xoa.util.ToJson;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.Date;

@Controller
@RequestMapping("/PzKeyPetition")
public class PzKeyPetitionController {
    @InitBinder
    public void initBinder(WebDataBinder binder) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        dateFormat.setLenient(false);
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));   //true:允许输入空值，false:不能为空值
    }
    @Resource
    private PzKeyPetitionService pzKeyPetitionService;

    @ResponseBody
    @RequestMapping("/insert")
    public ToJson<PzKeyPetitionWithBLOBs> insertSelective(HttpServletRequest request, PzKeyPetitionWithBLOBs record){
        return pzKeyPetitionService.insertSelective(request,record);
    }
    @ResponseBody
    @RequestMapping("/deletebyid")
    public ToJson<PzKeyPetitionWithBLOBs> deleteByPrimaryKey(HttpServletRequest request, int keyPetitionsId){
        return pzKeyPetitionService.deleteByPrimaryKey(request,keyPetitionsId);
    }
    @ResponseBody
    @RequestMapping("/update")
    public ToJson<PzKeyPetitionWithBLOBs> updateByPrimaryKeySelective (HttpServletRequest request, PzKeyPetitionWithBLOBs record){
        return pzKeyPetitionService.updateByPrimaryKeySelective(request,record);
    }

    /**
     * 张丽军：导出
     * @param request
     * @param response
     * @param pzKeyPetitionWithBLOBs
     * @param page
     * @param pageSize
     * @param useFlag
     * @param export
     * @return
     */
    @ResponseBody
    @RequestMapping("/queryPzKeyPetition")
    public ToJson<PzKeyPetitionWithBLOBs> queryPzKeyPetition(HttpServletRequest request, HttpServletResponse response, PzKeyPetitionWithBLOBs pzKeyPetitionWithBLOBs, Integer page, Integer pageSize, boolean useFlag, String export, String pCardId, String pName){
        return pzKeyPetitionService.queryPzKeyPetition(request,response,pzKeyPetitionWithBLOBs,page,pageSize,useFlag,export,pCardId,pName);
    }
    @ResponseBody
    @RequestMapping("/selectbyid")
    public ToJson<PzKeyPetitionWithBLOBs> selectById(Integer keyPetitionsId, HttpServletRequest request){
        return pzKeyPetitionService.selectById(keyPetitionsId,request);}

    /**
     *张丽军： 导入
      * @param request
     * @param response
     * @param file
     * @param session
     * @return
     */
    @RequestMapping("/importKeyPetition")
    @ResponseBody
    public ToJson<PzKeyPetitionWithBLOBs> importKeyPetition(HttpServletRequest request, HttpServletResponse response, MultipartFile file, HttpSession session){
        return pzKeyPetitionService.importKeyPetition(request,response,file,session);
    }
}
